//
//  AppDelegate.m
//  MZJ
//
//  Created by XDD on 16/6/2.
//  Copyright © 2016年 XDD. All rights reserved.
//

#import "AppDelegate.h"
//#import "UMSocial.h"
//#import "UMSocialWechatHandler.h"
//#import "UMSocialQQHandler.h"
#import "LinkPageViewController.h"
#import "LoginViewController.h"
#import "TabBarViewController.h"
#import "FirstViewController.h"

@interface AppDelegate ()

@property(nonatomic, strong)UITabBarController *tabBarController;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //判断是不是第一次启动应用
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
        LinkPageViewController *viewController = [[LinkPageViewController alloc] init];
        self.window.rootViewController = viewController;
        [_window makeKeyAndVisible];
    }else {
        self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
        FirstViewController *firstViewController = [[FirstViewController alloc] init];
        self.window.rootViewController = firstViewController;
        [_window makeKeyAndVisible];
    }
    
    [GiFHUD setGifWithImageName:@"mzj.gif"];

    [BeeCloud initWithAppID:@"9803cb15-034b-41d1-bd2c-f45fc44a11d1" andAppSecret:@"5c5f1103-0757-40a4-a6ae-381c02d3fa0c"];
    [BeeCloud initWeChatPay:@"wxf817de90a75156e5"];
    [BeeCloud setWillPrintLog:YES];
    
    //设置友盟Appkey
//    [UMSocialData setAppKey:@"53290df956240b6b4a0084b3"];
//    
//    //设置微信AppId，设置分享url，默认使用友盟的网址
//    [UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];
//    
//    //设置手机QQ的AppId，指定你的分享url，若传nil，将使用友盟的网址
//    [UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"c7394704798a158208a74ab60104f0ba" url:@"http://www.umeng.com/social"];
//    
//    //如果你要支持不同的屏幕方向，需要这样设置，否则在iPhone只支持一个竖屏方向
//    [UMSocialConfig setSupportedInterfaceOrientations:UIInterfaceOrientationMaskAll];
 
    return YES;
}

//- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
//{
//    return  [UMSocialSnsService handleOpenURL:url];
//}
//
//- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
//{
//    return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
//}

//为保证从支付宝，微信返回本应用，须绑定openUrl.
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {

    
    if ([BeeCloud handleOpenUrl:url]) {
        //handle其他类型的url
//        [XJNetWorkingManager GetPersonalInfoWithPay_OK:[DataModel object].isToken bid:[DataModel object].billID successHandler:^(id responseObject) {
//            
//            NSLog(@"支付成功的回调 = %@",responseObject);
//        } failureHandler:^(NSError *error) {
//            
//        }];
    }
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
